package kmp;

import java.util.HashMap;

/**
 * 给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度。
 */
public class leetCode3_lengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        if(s == null || s.length() == 0) return 0;
        HashMap<Character,Integer> map = new HashMap<>();
        int left = 0;
        int right = 0;
        int length = s.length();
        int max = 0;
        while (right < length){
            char a = s.charAt(right);
            right++;
            map.put(a,map.getOrDefault(a,0) + 1);
            while (map.get(a) > 1){
                char b = s.charAt(left);
                left++;
                if(map.containsKey(b)){
                    map.put(b,map.get(b) - 1);
                }
            }
            max = Math.max(max,right - left);
        }
        return max;
    }

}
